package com.turnengine.client.local.property.command.set;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.ErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.local.property.command.GetLocalProperty;
import com.turnengine.client.local.property.command.IGetLocalProperty;
import com.turnengine.client.local.property.command.ISetLocalProperty;
import com.turnengine.client.local.property.command.SetLocalProperty;

/**
 * The Local Property Command Set.
 */
public class LocalPropertyCommandSet implements ILocalPropertyCommandSet {

	@Override
	public String setLocalProperty(long loginId, int instanceId, String key, String value) {
		ISetLocalProperty command = new SetLocalProperty(loginId, instanceId, key, value);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<String> response = service.execute(command);
		if (response.hasErrors()) {
			throw new ErrorCodeException(response);
		}
		return response.getReturnValue();
	}

	@Override
	public String getLocalProperty(long loginId, int instanceId, String key) {
		IGetLocalProperty command = new GetLocalProperty(loginId, instanceId, key);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<String> response = service.execute(command);
		if (response.hasErrors()) {
			throw new ErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
